from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
import sys
from PyQt5.QtCore import QSize, Qt
from random import choice

title_arr = list('ABCDE')


class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()

        self.setWindowTitle('My App')

        self.button = QPushButton('Press Me !!!')
        self.button.clicked.connect(self.the_button_was_clicked)
        self.windowTitleChanged.connect(self.the_window_title_changed)

        self.setMinimumSize(QSize(400, 300))
        self.setMaximumSize(QSize(600, 450))
        self.setCentralWidget(self.button)

    def the_button_was_clicked(self, *args):
        print('Clicked!', *args)
        title = choice(title_arr)
        print('Change title to:', title)
        self.setWindowTitle(title)
        # raise Exception("My intended exception")  # test. Yabari! It is now pure python that is running!

    def the_window_title_changed(self, *args):
        print('Window title changed:', *args)

app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec_()
